import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;

public class Player
{
	
	private Socket clientSocket = null;
	private BufferedReader in = null;
	private PrintWriter out = null;
	private String line = new String();
	private int playerId;
	
	private Hand hand;
	private int status;	//{ "" ,"Bet", "Raised", "All-in", "Folded", "Checked" , "Call"};
	public Player playerOnLeft;
	private int chips;
	private int bet;
	private boolean isDealer, isSmallBlind, isBigBlind;
	private String nick = new String();
	private boolean turn,allin,fold, check;
	
	
	Player(Socket sock, int i)
	{
		hand = new Hand();
		status = 0;
		clientSocket = sock;
		playerId = i;
		bet = 0;
		try
		{
			in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
			out = new PrintWriter(clientSocket.getOutputStream(), true);
		}
		catch(IOException e)
		{
			System.out.println("I/O error - throwing exception");
			System.exit(0);
		}
	}
	public void setStatus(int s)
	{
		status = s;
	}
	public int getStatus()
	{
		return status;
	}
	public void sendToServer(String s)
	{
		out.println(s);
	}
	public String getFromServer()
	{
		String s = new String();
		try
		{
			s = in.readLine();
		}
		catch(IOException e)
		{
			System.out.println("Playerd: " + playerId + " disconnected");
			return "Q";
		}
		return s;
	}
	public void closeConnection()
	{
		try
		 {
	    	 
			 in.close();
			 out.close();
			 clientSocket.close();
		 }
	     catch(IOException ex)
	     {
	    	 System.out.println("error in closing socket and I/O");
	     }
	}
	//****** private variables methods
	public int getChips()
	{
		return chips;
	}
	public void setChips(int c)
	{
		chips = c;
	}
	public void setDealer(boolean a)
	{
		isDealer = a;
	}
	public boolean isDealer()
	{
		return isDealer;
	}
	public void setSmallBlind(boolean a)
	{
		isSmallBlind = a;
	}
	public boolean isSmallBlind()
	{
		return isSmallBlind;
	}
	public void setBigBlind(boolean a)
	{
		isBigBlind = a;
	}
	public boolean isBigBlind()
	{
		return isBigBlind;
	}
	public int getPlayerId()
	{
		return playerId;
	}
	public void setCardInHand(int card, int cardId)
	{
		hand.setCard(card, cardId);
	}
	public void setNick(String s)
	{
		nick = s;
	}
	public String getNick()
	{
		return nick;
	}
	public Card getCardFromHand(int card)
	{
		return hand.getCard(card);
	}
	public void setTokenFalse()
	{
		isBigBlind = false;
		isSmallBlind = false;
		isDealer = false;
	}
	public void betChips(int ammount)
	{
		bet += ammount;
		chips -= ammount;
	}
	public int allIn()
	{
		bet += chips;
		int r = chips;
		chips = 0;
		status = 3;
		allin = true;
		return r;
	}
	public int getBet()
	{
		return bet;
	}
	public void setBet(int b)
	{
		bet = b;
	}
	public void setTurn(boolean t)
	{
		turn = t;
	}
	public boolean turn()
	{
		return turn;
	}
	public void setAllin(boolean b)
	{
		allin = b;
	}
	public boolean getAllin()
	{
		return allin;
	}
	public void setFold(boolean b)
	{
		fold = b;
		if (b==true) status = 4; else status = 0;
	}
	public boolean getFold()
	{
		return fold;
	}
	public void setCheck(boolean b)
	{
		check = b;
	}
	public boolean getCheck()
	{
		return check;
	}
	public int playersHandValue()
	{
		return hand.handValue();
	}
}
